<?php

use think\migration\Migrator;
use think\migration\db\Column;

class DealerGoodsSpec extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('dealer_goods_spec', ['engine' => 'InnoDB', 'comment' => '经销商商品规格表', 'signed' => false]);
        $table->addColumn('dealer_id', 'integer', ['default' => 0, 'comment' => '经销商id', 'signed' => false])
              ->addColumn('dealer_goods_id', 'integer', ['default' => 0, 'comment' => '经销商商品id', 'signed' => false])
              ->addColumn('goods_id', 'integer', ['default' => 0, 'comment' => '商品id', 'signed' => false])
              ->addColumn('spec_id', 'integer', ['default' => 0, 'comment' => '规格id', 'signed' => false])
              ->addColumn('name', 'string', ['default' => '', 'comment' => '规格名称', 'signed' => false])
              ->addColumn('sku', 'string', ['default' => '', 'comment' => 'sku码', 'signed' => false])
              ->addColumn('unit', 'string', ['default' => '', 'comment' => '单位', 'signed' => false])
              ->addColumn('box_num', 'integer', ['default' => 0, 'comment' => '箱柜数量', 'signed' => false])
              ->addColumn('is_single', 'integer', ['default' => 0, 'comment' => '是否单品:1是 2否', 'signed' => false])
              ->addColumn('weight', 'decimal', ['default' => 0, 'comment' => '重量(kg)', 'signed' => false])
              ->addColumn('length', 'decimal', ['default' => 0, 'comment' => '长(mm)', 'signed' => false])
              ->addColumn('width', 'decimal', ['default' => 0, 'comment' => '宽(mm)', 'signed' => false])
              ->addColumn('height', 'decimal', ['default' => 0, 'comment' => '高(mm)', 'signed' => false])
              ->addColumn('virtual_sales', 'integer', ['default' => 0, 'comment' => '虚拟销量', 'signed' => false])
              ->addColumn('actual_sales', 'integer', ['default' => 0, 'comment' => '实际销量', 'signed' => false])
              ->addColumn('purchase_price', 'decimal', ['default' => 0, 'comment' => '进价', 'signed' => false])
              ->addColumn('sale_price', 'decimal', ['default' => 0, 'comment' => '售价', 'signed' => false])
              ->addColumn('min_quantity', 'integer', ['default' => 0, 'comment' => '起订量', 'signed' => false])
              ->addColumn('remark', 'string', ['limit' => 255, 'default' => '', 'comment' => '备注', 'collation' => 'utf8mb4_general_ci'])
              ->addColumn('sort', 'integer', ['default' => 0, 'limit' => 10, 'comment' => '排序'])
              ->addColumn('status', 'integer', ['default' => 1, 'limit' => 1, 'comment' => '状态：1启用 2禁用'])
              ->addColumn('create_time', 'integer', ['default' => null, 'limit' => 10, 'comment' => '创建时间'])
              ->addColumn('update_time', 'integer', ['default' => null, 'limit' => 10, 'comment' => '更新时间'])
              ->addColumn('delete_time', 'integer', ['default' => null, 'limit' => 10, 'comment' => '删除时间'])
              ->addIndex('goods_id', ['name' => 'idx_goods_id'])
              ->addIndex('spec_id', ['name' => 'idx_spec_id'])
              ->addIndex('dealer_id', ['name' => 'idx_dealer_id'])
              ->addIndex('dealer_goods_id', ['name' => 'idx_dealer_goods_id'])
              ->addIndex('name', ['name' => 'idx_name'])
              ->addIndex('sku', ['name' => 'idx_sku'])
              ->create();
    }
}
